home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
076-100
/
disk_098
/
thai
/
random.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
1KB
|
63 lines
#include "quiz.h"
extern struct thai_phrase *random ();
random_sentence ()
{
chosen_sentence = random ( &sentence_head );
}
random_word ()
{
chosen_word = random ( &word_head );
}
static
struct thai_phrase *
random ( head )
struct thai_phrase *head;
{
long dist ();
long count;
long total_right;
long total_wrong;
long num;
static long seed = 0;
struct thai_phrase *p;
ULONG seconds , micros;
if ( head->next == NULL )
return ( head );
total_right = 0;
total_wrong = 0;
count = 0;
for ( p = head->next; p != NULL; p = p->next ) {
total_right += p->right;
total_wrong += p->wrong;
count++;
}
CurrentTime ( &seconds , µs );
seed += seconds + micros + 1234567;
num = ( seed & 0x7FFF ) % ( count + dist ( total_wrong , total_right ) );
for ( p = head->next; p != NULL; p = p->next ) {
num -= dist ( (long)p->wrong , (long)p->right ) + 1;
if ( num < 0 )
return ( p );
}
return ( head->next );
}
static long
dist ( wrong , right )
long wrong , right;
{
if ( wrong > right )
return ( wrong - right );
return ( 0 );
}